#include<iostream>
#include<vector>
#include<mutex>
#include<thread>
#include<functional>

using namespace std;

mutex mt;
condition_variable cv;
int n = 1;

void PrintOdd(string name)
{
    int cnt = 50;
    while (cnt--)
    {
        {
            unique_lock<mutex> lock(mt);
            cv.wait(lock, [&]() { return n % 2 == 1; });
            cout << name << " : " << n++ << endl;
        }

        cv.notify_all();
    }
}

void PrintEven(string name)
{
    int cnt = 50;
    while (cnt--)
    {
        {
            unique_lock<mutex> lock(mt);
            cv.wait(lock, [&]() { return n % 2 == 0; });
            cout << name << " : " << n++ << endl;
        }

        cv.notify_all();
    }
}

int main()
{

    thread t1(PrintOdd, "thread_1");
    thread t2(PrintEven, "thread_2");

    t1.join();
    t2.join();
    return 0;
}